"""
  Copyright (c) 2024 Northeastern University (China)
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
"""
# 任务：将oss收集到本地不做签名
# 是clone_oss,detector_by_ccscaner,find_deps_address的集成

import os
import sys

import click
from tqdm import tqdm

from src.common_utils.utils_file import read_jl
from src.oss_dataset_construction import detector_by_ccscaner as ccscaner
from src.oss_dataset_construction.clone_oss import Download
from src.oss_dataset_construction.find_deps_address import FindDepsAddress
from src.oss_dataset_construction import  detector_by_Centris as centris
from src.common_utils import configure
# 当前文件的路径
g_cur_dir = os.path.dirname(os.path.abspath(__file__))
# 当前文件的父路径
father_path = os.path.dirname(g_cur_dir)
sys.path.append(father_path)
def collect(count):
    for i in tqdm(range(0, count), total=10, desc="收集轮次"):
        # 先获取依赖项
        print("获取依赖项")
        # allprohects = allprojects = read_jl(g_cur_dir + r'\data_out\cloned_projects_paths.jl')
        allprojects = read_jl(os.path.join(configure.CONFIG['ossdb_construct'],'cloned_projects_paths.jl'))
        ccscaner.main_multi(projects=allprojects, num=4)
        # 之后寻找依赖项地址
        print("寻找依赖项地址")
        findDepsAddress = FindDepsAddress()
        findDepsAddress.main_multi(4)
        # 下载oss
        print("下载oss")
        download = Download()
        download.main_multithread(num_threads=8)
@click.command()
@click.option('--count', type=int, required=True, help='循环收集的轮次')
def main(count):
    collect(count)
    # print(sys.path)


if __name__ == "__main__":
     main()

